package searchEngine;
import java.util.HashSet;
import java.util.regex.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class SearchEngine {
	
	public static HashSet<StringBuffer> search(String searchExpr, String Url ) throws MalformedURLException, IOException {
		URL u = new URL(Url);
		return search(searchExpr, u);
	}	
	public static HashSet<StringBuffer> search(String searchExpr, URL Url ) throws IOException {	
		
		Pattern agentBlock = Pattern.compile(searchExpr);
		StringBuffer urlSource = utils.ReaderFactory.readUrlData(Url, "ISO-8859-1");
		Matcher agentsMatcher = agentBlock.matcher(urlSource);
		HashSet<StringBuffer> searchResults = new HashSet<StringBuffer>();
		
		while (agentsMatcher.find()) {
			searchResults.add(new StringBuffer(agentsMatcher.group()));
		}
		
		return searchResults;
	}

}
